package com.ruoyi.system.mapper;

import com.ruoyi.system.domain.SysCertificate;
import com.ruoyi.system.domain.Work;
import com.ruoyi.system.domain.mongodb.Works;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.List;
import java.util.Map;

/**
 * 大赛作品信息
 */
public interface WorkMapper {

    /**
     * 根据作品id查询作品信息
     */
    public Work queryWorkByWorkid(SysCertificate sysCertificate);

    /**
     * 根据赛事id查询是否有大众评审作品
     */
    public List<Work> queryReviewWorkByEpid(Integer epid);

    /**
     * 根据大赛id查询作品信息(填充下拉框)
     */
    public List<Work> selectWorkByEpid(Integer epid);

    /**
     * 增加大赛作品投票数
     */
    public void addVoteCount(Work work);


    /**
     * 改变作品状态为大众评审作品
     */
    public void updateReviewStateByWorkId(String workid);

    /**
     * 教师端根据教师id查询待评审作品信息
     * @param work
     * @return
     */
    public List<Work> queryWorksByTid(Work work);

    /**
     * 教师端根据教师id查询待评审作品信息(校园管理员)
     * @param work
     * @return
     */
    public List<Work> queryWorksByTidForAdmin(Work work);

    /**
     * 查询所有大赛作品信息
     * @param work
     * @return
     */
    public List<Work> queryWorks(Work work);

    /**
     * 查询管理员所有大赛作品信息
     * @param work
     * @return
     */
    public List<Work> queryWorksForAdmin(Work work);

    /**
     * 根据用户id,查询负责赛事下的所有作品id
     */
    public List<String> queryWorkIdByUserId(long userId);

    /**
     * 根据大赛id查询作品信息
     */
    public List<Work> queryWorkByEpid(Integer epid);

    /**
     * 根据大赛id查询参加大众评审的作品信息
     */
    public List<Map<String, Object>> queryPublicReviewWorkByEpid(@Param("epid") Integer epid,@Param("event_step") String event_step);

    /**
     * 根据作品id修改投票数
     */
    public void updateVote(String work_id);

    /**
     * 增加
     * */
    @Insert("insert into work(work_id,sid,epid,title,abstracts,`explain`,work_state,scoring_step,worksid, cover_id, group_id) values (#{work_id},#{sid},#{epid},#{title},#{abstracts},#{explain},#{work_state},#{scoring_step},#{worksid},#{cover_id}, #{group_id})")
    public Integer saveWorks(Work work);

    @Select("select * from work where scoring_step = #{scoring_step} and sid = #{sid} and epid = #{epid}")
    public Work selectWorkByWorkIdAndSidAndEpId(Map<String, String> map);


    @Delete("<script>delete from work where sid = #{userId} and epid = #{epId} " +
            " <if test='scoring_step!=null and scoring_step!=\"\"'>" +
            "   and scoring_step = #{scoring_step}" +
            "</if>" +
            "</script>")
    public Integer deleteEpIdAndSid(@Param("userId") String userId,@Param("epId") Integer epId, @Param("scoring_step") String scoring_step);


    @Select("select * from work where sid = #{userId} and epid = #{epId}")
    public Work selectEpIdAndSid(@Param("userId") String userId,@Param("epId") Integer epId);

    /**
     * 根据学ID查询他参赛的作品列表
     * @param sid 学生ID
     * @return
     */
    @Select("select w.*, e.eptitle from work w left join events_posted e on w.epid = e.epid where sid = #{sid}")
    List<Work> selectWorkBySid(@Param("sid") String sid);
}
